import QtQuick 2.12
import QtQuick.Controls 2.5
import AIClient.module 1.0
import QtQuick.Dialogs 1.3
import QtQuick.Layouts 1.12
import QtCharts 2.0

Page {
    id: dashboard_page
    width: parent.width*0.9
    height: parent.height*0.9

    title: qsTr("总览")
    anchors.fill: parent

    property int m_cpu_alloc: 2
    property int m_cpu_total: 6
    property int m_cpu_per_max: 1

    property int m_gpu_alloc: 2
    property int m_gpu_total: 5
    property int m_gpu_per_max: 1

    property double m_men_alloc: 3
    property double m_men_total: 5
    property double m_men_per_max: 1

    signal updateContent()
    signal myDataset()
    signal myGrantDataset()
    signal myModel()
    signal myGrantModel()
    signal myTrainjob()
    signal myApplication()

    function setComputerSource(cpu_alloc, cpu_total, cpu_per_max, men_alloc, men_total, men_per_max, gpu_alloc, gpu_total, gpu_per_max)
    {
        m_cpu_alloc = cpu_alloc
        m_cpu_total = cpu_total
        m_cpu_per_max = cpu_per_max

        m_gpu_alloc = gpu_alloc
        m_gpu_total = gpu_total
        m_gpu_per_max = gpu_per_max

        m_men_alloc = men_alloc
        m_men_total = men_total
        m_men_per_max = men_per_max
        //computer_source = "CPU可分配个数："+cpu_alloc+"\n"+"CPU总个数："+cpu_total+"\n"+"CPU单次最大分配个数："+cpu_per_max+"\n"+"内存可分配大小："+men_alloc+"\n"+"内存总大小："+men_total+"\n"+"内存单次分配最大量："+men_per_max+"\n"
    }

    function setDataset(my, grant)
    {
        mydataset.text = "我创建的数据集数量：" + my
        mygrantdataset.text = "我被授权的数据集数量："+grant
    }

    function setModel(my, grant)
    {
        mymodel.text = "我创建的模型数量：" + my
        mygrantmodel.text = "我被授权的模型数量：" + grant
    }

    function setTrainjob(my)
    {
        mytrainjob.text = "我创建的训练任务数量：" + my
    }

    function setApplication(my)
    {
        myapp.text = "我创建的AI应用数量：" + my
    }


    Rectangle{
        anchors.centerIn: parent
        width: parent.width
        height: parent.height
        color: "white"

        GridLayout {
            id: grid
            columns: 4
            rows: 2
            columnSpacing: 15
            rowSpacing: 15
            anchors.fill: parent
            anchors.leftMargin: 60
            anchors.rightMargin: 60
            anchors.topMargin: 50
            anchors.bottomMargin: 50
            Rectangle {
                Layout.row: 0
                Layout.column: 0
                Layout.columnSpan: 4
                Layout.minimumHeight: 200
                Layout.maximumHeight: 600
                Layout.preferredHeight: 350
                //                Layout.maximumWidth: 300
                Layout.fillWidth: true
                Layout.fillHeight: true
                color: "white"

                Rectangle {
                    anchors.top: parent.top
                    height: 60
                    width: parent.width
                    color: "silver"
                    Text {
                        anchors.verticalCenter: parent.verticalCenter
                        x: 30
                        text: "计算机资源"
                        color: "black"
                        font.pixelSize: 22
                        font.bold: true
                    }
                }
                Rectangle {
                    anchors.bottom: parent.bottom
                    height: parent.height - 60
                    width: parent.width
                    color: "aliceblue"
                    GridLayout {
                        anchors.fill: parent
                        rowSpacing: 10
                        columnSpacing: 10
                        rows: 2
                        columns: 3
                        Rectangle {
                            Layout.row: 1
                            Layout.column: 0
                            Layout.fillHeight: true
                            Layout.preferredWidth: 200
                            Layout.maximumWidth: 250
                            Layout.fillWidth: true
                            color: "transparent"
                            Text {
                                anchors.top: parent.top
                                text: "CPU可分配核数："+m_cpu_alloc+"\n\nCPU总核数："+m_cpu_total+"\n\nCPU单次可分配最大核数："+m_cpu_per_max
                                height: parent.height
                                x: 30
                                verticalAlignment: Qt.AlignVCenter
                                font.pixelSize: 20
                                //font.bold: true
                                color: "gray"

                            }
                        }
                        ChartView {
                            Layout.row: 0
                            Layout.column: 0
                            Layout.fillHeight: true
                            Layout.preferredWidth: 500
                            Layout.maximumWidth: 500
                            Layout.fillWidth: true
                            //anchors.fill: parent
                            theme: ChartView.ChartThemeLight
                            antialiasing: true
                            legend.visible: true
                            animationOptions: ChartView.AllAnimations
                            //title: "CPU资源情况"

                            backgroundColor: "transparent"
                            PieSeries {
                                id: pieSeries
                                holeSize: 0.35
                                PieSlice {
                                    borderColor: "#AAAAAA"
                                    //color: "#804040"
                                    label: qsTr("CPU已使用 " + (((m_cpu_total-m_cpu_alloc))/m_cpu_total*100).toFixed(2) + "%")
                                    labelVisible: false

                                    value: ((m_cpu_total-m_cpu_alloc))/m_cpu_total

                                }
                                PieSlice {
                                    borderColor: "#AAAAAA"
                                    //color: "#408040"
                                    label: qsTr("CPU未使用 " + (m_cpu_alloc/m_cpu_total*100).toFixed(2) + "%")
                                    labelVisible: false
                                    value: m_cpu_alloc/m_cpu_total
                                }
                            }
                        }

                        Rectangle {
                            Layout.row: 1
                            Layout.column: 1
                            Layout.fillHeight: true
                            Layout.preferredWidth: 200
                            Layout.maximumWidth: 250
                            Layout.fillWidth: true
                            color: "transparent"
                            Text {
                                anchors.top: parent.top
                                text: "内存可分配量(MB)："+m_men_alloc+"\n\n内存总量(MB)："+m_men_total+"\n\n内存单次可分配最大量(MB)："+m_men_per_max
                                height: parent.height
                                x: 30
                                verticalAlignment: Qt.AlignVCenter
                                font.pixelSize: 20
                                font.bold: false
                                color: "gray"

                            }
                        }
                        ChartView {
                            Layout.row: 0
                            Layout.column: 1
                            Layout.fillHeight: true
                            Layout.preferredWidth: 500
                            Layout.maximumWidth: 500
                            Layout.fillWidth: true
                            //anchors.fill: parent
                            theme: ChartView.ChartThemeLight
                            antialiasing: true
                            legend.visible: true
                            animationOptions: ChartView.AllAnimations
                            //title: "CPU资源情况"

                            backgroundColor: "transparent"
                            PieSeries {
                                id: pieSeries2
                                holeSize: 0.35
                                PieSlice {
                                    borderColor: "#AAAAAA"
                                    color: "palegoldenrod"
                                    label: qsTr("内存已使用 " + (((m_men_total-m_men_alloc))/m_men_total*100).toFixed(2) + "%")
                                    labelVisible: false

                                    value: ((m_men_total-m_men_alloc))/m_men_total

                                }
                                PieSlice {
                                    borderColor: "#AAAAAA"
                                    color: "salmon"
                                    label: qsTr("内存未使用 " + (m_men_alloc/m_men_total*100).toFixed(2) + "%")
                                    labelVisible: false
                                    value: m_men_alloc/m_men_total
                                }
                            }
                        }


                        Rectangle {
                            Layout.row: 1
                            Layout.column: 2
                            Layout.fillHeight: true
                            Layout.preferredWidth: 200
                            Layout.maximumWidth: 250
                            Layout.fillWidth: true
                            color: "transparent"
                            Text {
                                anchors.top: parent.top
                                text: "GPU可分配个数："+m_gpu_alloc+"\n\nGPU总个数："+m_gpu_total+"\n\nGPU单次可分配最大个数："+m_gpu_per_max
                                height: parent.height
                                x: 30
                                verticalAlignment: Qt.AlignVCenter
                                font.pixelSize: 20
                                font.bold: false
                                color: "gray"

                            }
                        }
                        ChartView {
                            Layout.row: 0
                            Layout.column: 2
                            Layout.fillHeight: true
                            Layout.preferredWidth: 500
                            Layout.maximumWidth: 500
                            Layout.fillWidth: true
                            //anchors.fill: parent
                            theme: ChartView.ChartThemeLight
                            antialiasing: true
                            legend.visible: true
                            animationOptions: ChartView.AllAnimations
                            //title: "CPU资源情况"

                            backgroundColor: "transparent"
                            PieSeries {
                                id: pieSeries3
                                holeSize: 0.35

                                PieSlice {
                                    borderColor: "#AAAAAA"
                                    color: "greenyellow"
                                    label: qsTr("GPU已使用 " + (((m_gpu_total-m_gpu_alloc))/m_gpu_total*100).toFixed(2) + "%")
                                    labelVisible: false

                                    value: ((m_gpu_total-m_gpu_alloc))/m_gpu_total

                                }
                                PieSlice {

                                    borderColor: "#AAAAAA"
                                    color: "seagreen"
                                    label: qsTr("GPU未使用 " + (m_gpu_alloc/m_gpu_total*100).toFixed(2) + "%")
                                    labelVisible: false
                                    value: m_gpu_alloc/m_gpu_total
                                }
                            }
                        }

                    }

                    //                    TextArea {
                    //                        id: computer_source
                    //                        anchors.top: parent.top
                    //                        height: 60
                    //                        enabled: false
                    //                        background: Rectangle{
                    //                            color: "transparent"
                    //                            anchors.fill: parent.top
                    //                            height: 60
                    //                        }
                    //                    }

                }
            }

            Rectangle {
                Layout.row: 1
                Layout.column: 0
                Layout.minimumHeight: 300
                Layout.maximumHeight: 500
                Layout.preferredHeight: 300
                Layout.maximumWidth: 400
                Layout.fillWidth: true
                color: "white"

                Rectangle {
                    anchors.top: parent.top
                    height: 60
                    width: parent.width
                    color: "lightskyblue"
                    Text{
                        anchors.verticalCenter: parent.verticalCenter
                        x: 30
                        text: "数据集"
                        color: "black"
                        font.pixelSize: 22
                        font.bold: true
                    }
                }
                Rectangle {
                    anchors.bottom: parent.bottom
                    height: parent.height - 60
                    width: parent.width
                    color: "aliceblue"
                    Text {
                        id: mydataset
                        anchors.top: parent.top
                        height: 100
                        width: parent.width - 60
                        x: 30
                        verticalAlignment: Qt.AlignVCenter
                        font.pixelSize: 20
                        font.bold: false
                        color: "gray"
                        MouseArea {
                            id: ma_mydataset
                            anchors.fill: mydataset
                            onClicked: {
                                myDataset()
                            }
                            hoverEnabled: true
                            onEntered: {
                                mydataset.color = "blue"
                                mydataset.font.underline = true
                            }
                            onExited: {
                                mydataset.color = "gray"
                                mydataset.font.underline = false
                            }

                            cursorShape: hovered?Qt.PointingHandCursor:Qt.ArrowCursor
                        }
                    }
                    Text {
                        id: mygrantdataset
                        anchors.top: mydataset.bottom
                        height: 100
                        width: parent.width
                        x: 30
                        verticalAlignment: Qt.AlignVCenter
                        font.pixelSize: 20
                        font.bold: false
                        color: "gray"
                        MouseArea {
                            id: ma_grantdataset
                            anchors.fill: mygrantdataset
                            onClicked: {
                                myGrantDataset()
                            }
                            hoverEnabled: true
                            onEntered: {
                                mygrantdataset.color = "blue"
                                mygrantdataset.font.underline = true
                            }
                            onExited: {
                                mygrantdataset.color = "gray"
                                mygrantdataset.font.underline = false
                            }

                            cursorShape: hovered?Qt.PointingHandCursor:Qt.ArrowCursor
                        }
                    }

                }
            }


            Rectangle {
                Layout.row: 1
                Layout.column: 1
                Layout.minimumHeight: 300
                Layout.maximumHeight: 500
                Layout.preferredHeight: 300
                Layout.maximumWidth: 400
                Layout.fillWidth: true
                color: "white"

                Rectangle {
                    anchors.top: parent.top
                    height: 60
                    width: parent.width
                    color: "lightsalmon"
                    Text{
                        anchors.verticalCenter: parent.verticalCenter
                        x: 30
                        text: "模型"
                        color: "black"
                        font.pixelSize: 22
                        font.bold: true
                    }
                }
                Rectangle {
                    anchors.bottom: parent.bottom
                    height: parent.height - 60
                    width: parent.width
                    color: "aliceblue"
                    Text {
                        id: mymodel
                        anchors.top: parent.top
                        height: 100
                        width: parent.width - 60
                        x: 30
                        verticalAlignment: Qt.AlignVCenter
                        font.pixelSize: 20
                        font.bold: false
                        color: "gray"
                        MouseArea {
                            id: ma_mymodel
                            anchors.fill: mymodel
                            onClicked: {
                                myModel()
                            }
                            hoverEnabled: true
                            onEntered: {
                                mymodel.color = "blue"
                                mymodel.font.underline = true
                            }
                            onExited: {
                                mymodel.color = "gray"
                                mymodel.font.underline = false
                            }

                            cursorShape: hovered?Qt.PointingHandCursor:Qt.ArrowCursor
                        }
                    }
                    Text {
                        id: mygrantmodel
                        anchors.top: mymodel.bottom
                        height: 100
                        width: parent.width
                        x: 30
                        verticalAlignment: Qt.AlignVCenter
                        font.pixelSize: 20
                        font.bold: false
                        color: "gray"
                        MouseArea {
                            id: ma_grantmodel
                            anchors.fill: mygrantmodel
                            onClicked: {
                                myGrantModel()
                            }
                            hoverEnabled: true
                            onEntered: {
                                mygrantmodel.color = "blue"
                                mygrantmodel.font.underline = true
                            }
                            onExited: {
                                mygrantmodel.color = "gray"
                                mygrantmodel.font.underline = false
                            }

                            cursorShape: hovered?Qt.PointingHandCursor:Qt.ArrowCursor
                        }
                    }

                }
            }


            Rectangle {
                Layout.row: 1
                Layout.column: 2
                Layout.minimumHeight: 300
                Layout.maximumHeight: 500
                Layout.preferredHeight: 300
                Layout.maximumWidth: 400
                Layout.fillWidth: true
                color: "white"

                Rectangle {
                    anchors.top: parent.top
                    height: 60
                    width: parent.width
                    color: "aquamarine"

                    Text{
                        anchors.verticalCenter: parent.verticalCenter
                        x: 30
                        text: "训练任务"
                        color: "black"
                        font.pixelSize: 22
                        font.bold: true
                    }
                }
                Rectangle {
                    anchors.bottom: parent.bottom
                    height: parent.height - 60
                    width: parent.width
                    color: "aliceblue"
                    Text {
                        id: mytrainjob
                        anchors.top: parent.top
                        height: 100
                        width: parent.width - 60
                        x: 30
                        verticalAlignment: Qt.AlignVCenter
                        font.pixelSize: 20
                        font.bold: false
                        color: "gray"
                        MouseArea {
                            id: ma_mytrainjob
                            anchors.fill: mytrainjob
                            onClicked: {
                                myTrainjob()
                            }
                            hoverEnabled: true
                            onEntered: {
                                mytrainjob.color = "blue"
                                mytrainjob.font.underline = true
                            }
                            onExited: {
                                mytrainjob.color = "gray"
                                mytrainjob.font.underline = false
                            }
                            cursorShape: hovered?Qt.PointingHandCursor:Qt.ArrowCursor
                        }
                    }
                }
            }


            Rectangle {
                Layout.row: 1
                Layout.column: 3
                Layout.minimumHeight: 300
                Layout.maximumHeight: 500
                Layout.preferredHeight: 300
                Layout.maximumWidth: 400
                Layout.fillWidth: true
                color: "white"

                Rectangle {
                    anchors.top: parent.top
                    height: 60
                    width: parent.width
                    color: "sandybrown"
                    Text{
                        anchors.verticalCenter: parent.verticalCenter
                        x: 30
                        text: "AI应用"
                        color: "black"
                        font.pixelSize: 22
                        font.bold: true
                    }
                }
                Rectangle {
                    anchors.bottom: parent.bottom
                    height: parent.height - 60
                    width: parent.width
                    color: "aliceblue"
                    Text {
                        id: myapp
                        anchors.top: parent.top
                        height: 100
                        width: parent.width - 60
                        x: 30
                        verticalAlignment: Qt.AlignVCenter
                        font.pixelSize: 20
                        font.bold: false
                        color: "gray"
                        MouseArea {
                            id: ma_myapp
                            anchors.fill: myapp
                            onClicked: {
                                myApplication()
                            }
                            hoverEnabled: true
                            onEntered: {
                                myapp.color = "blue"
                                myapp.font.underline = true
                            }
                            onExited: {
                                myapp.color = "gray"
                                myapp.font.underline = false
                            }
                            cursorShape: hovered?Qt.PointingHandCursor:Qt.ArrowCursor
                        }
                    }
                }
            }




        }


    }
}
